package com.jml.第二期.utils;

import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class 手写jwt {
    /**
     * https://jwt.io/
     * @param args
     */
    public static void main(String[] args) throws UnsupportedEncodingException {
        //定义header
        JSONObject header = new JSONObject();
        header.put("alg","HS256");
        //定义payload
        JSONObject payload = new JSONObject();
        payload.put("phone","188xxxx0000");
        String headerEncoder = Base64.getEncoder().encodeToString(header.toJSONString().getBytes());
        String payloadEncoder = Base64.getEncoder().encodeToString(payload.toJSONString().getBytes());
        //签名
        String sign = MD5Util.encode(payloadEncoder);
        String jwt = headerEncoder+"."+payloadEncoder+"."+sign;
        System.out.println(jwt);
    }
}
